/*
 * @Description: 第一章入门
 * @Author: IA ia@ker.center
 * @Date: 2025-02-25 16:22:35
 */
import { createApp, createVNode, render } from "vue";
import App from "./App.vue";
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import loadingBar from '@/components/loadingBar.vue'


console.log('main.ts loadingBar : ', loadingBar)

const loadingBarVNode = createVNode(loadingBar)

console.log('main.ts loadingBar createVNode VNode : ', loadingBarVNode)

render(loadingBarVNode, document.body)


let app = createApp(App);
app.use(router)
app.use(ElementPlus)

// 第八章-导航守卫

const whiteList = [
    '/login'
]

// 全局前置守卫
router.beforeEach((to, from, next) => {
    loadingBarVNode.component?.exposed?.startLoading()
    if (whiteList.includes(to.path) || localStorage.getItem('token')) {
        next()
    } else {
        next('/login')
    }

    console.log('main.ts router.beforeEach to: ', to);
    document.title = to.meta.title

    
})


// 全局后置守卫
router.afterEach((to, from) => {
    loadingBarVNode.component?.exposed?.endLoading()
})

app.mount("#app");
